﻿function gerpUtility() {

    this.testValue = "field testValue in class gerpUtility";

    this.convertStringToDate = function (dateStr) {
        if (dateStr == "") {
            return new Date();
        }
        var rawStr1 = dateStr.split("/");
        var rawStr2 = rawStr1[2].split(" ");
        rawStr1[2] = rawStr2[0];
        var day = rawStr1[0];
        var month = rawStr1[1];
        var year = rawStr1[2];

        var result = new Date(this.getJsYear(year), this.getJsMonth(month), day);
        return result;
    };

    this.paddingNumber = function (n, width, z) {
        z = z || '0';
        n = n + '';
        return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
    };

    this.getDayOfWeekWord = function (d) {

        var weekday = new Array(7);
        weekday[0] = "Sunday";
        weekday[1] = "Monday";
        weekday[2] = "Tuesday";
        weekday[3] = "Wednesday";
        weekday[4] = "Thursday";
        weekday[5] = "Friday";
        weekday[6] = "Saturday";

        return weekday[d.getDay()];
    };

    this.getDatePickerStringFormat = function (d) {
        return this.paddingNumber(d.getDate(), 2, 0) + "/" +
			this.paddingNumber(this.getMonth(d), 2, 0) + "/" + this.getYear(d);
    };

    this.getMonth = function (d) {
        return d.getMonth() + 1;
    };

    this.getYear = function (d) {
        return d.getFullYear() + 543;
    };

    this.getJsMonth = function (numberMonth) {
        return numberMonth - 1;
    };

    this.getJsYear = function (numberYear) {
        if (numberYear.length == 2) numberYear = "25" + numberYear;
        else if (numberYear < 2400) numberYear = numberYear + 543;
        return numberYear - 543;
    };
}